<?php

namespace app\common\job;

use app\common\logic\comic\ComicLogic;
use think\Log;
use think\queue\Job;

class ImportChapterZip
{
    public function fire(Job $job, $data)
    {
        try {
            $path = $data['path'] ?? null;
            if (!$path) {
                throw new \Exception("path参数错误");
            }

            $comicId = $data['comic_id'] ?? null;

            if (!$comicId) {
                throw new \Exception("comic_id参数错误");
            }

            $comicLogic = new ComicLogic();

            if (!$comicLogic->chapterImportZip($comicId, $path)) {
                throw new \Exception($comicLogic->getMessage());
            }
        } catch (\Throwable $exception) {
            Log::error(sprintf(
                '[ImportChapterZip]执行失败:%s',
                $exception->getMessage(),
            ));
        }
        $job->delete();
    }
}